package com.lvcoding.auth2.jpah2;

import com.lvcoding.auth2.jpah2.dao.AccountRepository;
import com.lvcoding.auth2.jpah2.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author wuyanshen
 * @description 描述
 * @date 2022-02-22 上午11:04
 */
@SpringBootApplication
public class SingleAuthH2JpaApp implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(SingleAuthH2JpaApp.class, args);
    }

    @Autowired
    AccountRepository accountRepository;

    @Autowired
    PasswordEncoder passwordEncoder;

    @Override
    public void run(String... args) throws Exception {
        accountRepository.deleteAll();
        accountRepository.save(new Account("admin", passwordEncoder.encode("admin")));

        System.out.println("it works");
    }
}
